package jp.co.sega.sonic_jump.monthly.sum.PlatformStandard;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import jp.co.sega.sonic_jump.monthly.sum.Device;
import jp.co.sega.sonic_jump.monthly.sum.Game_Draw;
import jp.co.sega.sonic_jump.monthly.sum.Graphics;
import jp.co.sega.sonic_jump.monthly.sum.R;

public class Standard {
    public static final int IMG_CMCC = 0;
    public static final int IMG_CP = 1;
    public static final int MAX_STAR_NUM = 5;
    public static final boolean MENU_MORE_GAME = false;
    public static final int PER_LOGO_TIME = 2000;
    public static final int R_MOREGAME_EXIT = 0;
    public static final int R_MOREGAME_WAIT = 1;
    public static final int R_PAY_CANCEL = 1;
    public static final int R_PAY_FINISH = 2;
    public static final int R_PAY_WAIT = 0;
    public static final int R_SPLASH_END = 3;
    public static final int R_SPLASH_IS_EMU = 4;
    public static final int R_SPLASH_SOUND_DISABLE = 2;
    public static final int R_SPLASH_SOUND_ENABLE = 1;
    public static final int R_SPLASH_WAIT = 0;
    public static int SCREEN_H = 0;
    public static int SCREEN_W = 0;
    public static final int SHOW_LOGO_TIME = 2000;
    public static final int SOFT_KEY_HEIGHT = 17;
    public static final int SPLASH_EVALUATE = 1;
    public static final int SPLASH_INIT = 0;
    public static final int SPLASH_IS_EMU = 5;
    public static final int SPLASH_NORMAL = 4;
    public static final int SPLASH_SOUND = 2;
    public static final int STAR_HEIGHT = 30;
    public static final int STAR_OFFSET = 30;
    public static final int STAR_WIDTH = 14;
    private static String[] SplashImageName = {"sp", "cp"};
    private static boolean keyCancel;
    private static boolean keyConfirm;
    private static long lastTime;
    private static Resources m_res;
    private static int[] normalLogoImgIndex = {1, 1};
    private static long nowTime;
    private static BitmapFactory.Options option = new BitmapFactory.Options();
    private static boolean pause = false;
    private static int[] softValue = new int[2];
    public static boolean splashEnd;
    private static int splashImageLoadCount;
    private static Bitmap[] splashImages;
    private static int splashState;
    private static int timeCount;
    private static long timePeriod;

    public static void setResources(Resources res) {
        m_res = res;
    }

    public static void pressConfirm() {
        keyConfirm = true;
    }

    public static void pressCancel() {
        keyCancel = true;
    }

    public void setSoftValue(int lValue, int rValue) {
        softValue[0] = lValue;
        softValue[1] = rValue;
    }

    public static void pause() {
        pause = true;
    }

    public static void resume() {
        pause = false;
        nowTime = System.currentTimeMillis();
        lastTime = nowTime;
        timePeriod = 0;
    }

    public static int execSplash() {
        nowTime = System.currentTimeMillis();
        timePeriod = nowTime - lastTime;
        if (timePeriod > 100) {
            timePeriod = 100;
        }
        int ret = 0;
        if (!pause) {
            switch (splashState) {
                case 0:
                    splashImages = new Bitmap[SplashImageName.length];
                    splashImageLoadCount = 0;
                    splashState = 1;
                    timeCount = 0;
                    break;
                case 1:
                    if (splashImageLoadCount >= splashImages.length) {
                        splashState = 2;
                        break;
                    } else {
                        try {
                            splashImages[splashImageLoadCount] = BitmapFactory.decodeResource(m_res, R.drawable.class.getField(SplashImageName[splashImageLoadCount]).getInt((Object) null), option);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        splashImageLoadCount++;
                        break;
                    }
                case 2:
                    if (!keyConfirm) {
                        if (keyCancel) {
                            splashState = 4;
                            ret = 2;
                            break;
                        }
                    } else {
                        splashState = 4;
                        ret = 1;
                        break;
                    }
                    break;
                case 4:
                    timeCount = (int) (((long) timeCount) + timePeriod);
                    if (timeCount > 2000) {
                        for (int i = 0; i < splashImages.length; i++) {
                            splashImages[i] = null;
                        }
                        splashImages = null;
                        if (!isEmulator()) {
                            ret = 3;
                            splashState = 0;
                            break;
                        } else {
                            splashState = 5;
                            break;
                        }
                    }
                    break;
                case 5:
                    if (keyConfirm) {
                        splashState = 0;
                        ret = 4;
                        break;
                    }
                    break;
            }
        }
        lastTime = nowTime;
        keyConfirm = false;
        keyCancel = false;
        return ret;
    }

    public static void drawSplash(Graphics g, int SCREEN_W2, int SCREEN_H2) {
        g.wg_setFontSize(40);
        g.setColor(Game_Draw.Color_White);
        g.fillRect(0, 0, SCREEN_W2, SCREEN_H2);
        switch (splashState) {
            case 2:
                g.setColor(0);
                g.drawString("是", 1.0f, (float) (SCREEN_H2 - 1), 16640);
                g.drawString("否", (float) (SCREEN_W2 - 1), (float) (SCREEN_H2 - 1), 20480);
                g.setColor(0);
                g.drawString("开启声音?", (float) (SCREEN_W2 / 2), (float) ((SCREEN_H2 / 2) + 20), 1536);
                drawSoundIcon(g, SCREEN_W2, SCREEN_H2);
                return;
            case 4:
                if (timeCount < 2000) {
                    g.drawImage(splashImages[normalLogoImgIndex[timeCount / 2000]], (float) (SCREEN_W2 / 2), (float) (SCREEN_H2 / 2), 8704);
                    return;
                }
                return;
            case 5:
                g.setColor(0);
                g.drawString("请用手机玩游戏", (float) (SCREEN_W2 / 2), (float) (SCREEN_H2 / 2), 1536);
                return;
            default:
                return;
        }
    }

    public static int execMoreGame(boolean openWapAvailable) {
        return 0;
    }

    public static void drawMoreGame(Graphics g, int SCREEN_W2, int SCREEN_H2) {
    }

    public static void openMoreGameUrl(Activity midlet) {
    }

    public static void menuMoreGameSelected() {
    }

    private static void drawSoundIcon(Graphics g, int screen_w, int screen_h) {
        int x = (screen_w >> 1) - 32;
        int y = (screen_h >> 1) - 48;
        g.setColor(5263440);
        g.fillRoundRect(x - 1, y - 1, 66, 66, 16, 16);
        g.setColor(Game_Draw.Color_White);
        g.fillRoundRect(x, y, 64, 64, 16, 16);
        g.setColor(22708);
        g.fillRoundRect(x + 2, y + 2, 60, 60, 16, 16);
        g.setColor(5263440);
        int y2 = y + 2;
        g.fillArc(x + 12, y2 + 36, 16, 16, 0, Device.SCREEN_RESOLUTION);
        g.fillArc(x + 36, y2 + 32, 16, 16, 0, Device.SCREEN_RESOLUTION);
        g.drawLine(x + 12 + 8, y2 + 36 + 8, x + 12 + 16, y2 + 36 + 8);
        g.drawLine(x + 36 + 8, y2 + 32 + 8, x + 36 + 16, y2 + 32 + 8);
        g.fillRect(x + 24, y2 + 12, 4, 34);
        g.fillRect(x + 24, y2 + 12, 24, 4);
        g.fillRect(x + 48, y2 + 12, 4, 26);
        g.setColor(Game_Draw.Color_White);
        int x2 = x - 2;
        int y3 = y2 - 2;
        g.fillArc(x2 + 12, y3 + 36, 16, 16, 0, Device.SCREEN_RESOLUTION);
        g.fillArc(x2 + 36, y3 + 32, 16, 16, 0, Device.SCREEN_RESOLUTION);
        g.fillRect(x2 + 24, y3 + 12, 4, 34);
        g.fillRect(x2 + 24, y3 + 12, 24, 4);
        g.fillRect(x2 + 48, y3 + 12, 4, 26);
        int y4 = y3 + 72;
    }

    private static boolean isEmulator() {
        boolean isEmu = false;
        String platform = System.getProperty("microedition.platform");
        if (platform != null && ((platform.toLowerCase().equals("j2me") && Runtime.getRuntime().totalMemory() == 8000000) || platform.toLowerCase().endsWith("javasdk") || platform.toLowerCase().endsWith("wtk"))) {
            isEmu = true;
        }
        try {
            Class.forName("emulator.Emulator");
            return true;
        } catch (Exception e) {
            return isEmu;
        }
    }
}
